home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / text / tex / amiweb2c.lha / AmiWeb2c-2.1 / texmf / amiweb2c / rexx / makempx.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1998-03-08  |  6.5 KB  |  214 lines

  1. /*
  2.  * This AREXX script simulates the UNIX-sh script of the same name.
  3.  *
  4.  * MakeMPX -- make an MPX file from the labels in a MetaPost source file,
  5.  * using mpto and dvitomp (TeX) (sorry, troff not supported).
  6.  * Based on Karl Berry's version which is based on John Hobby's original
  7.  * (though there's not much of it left by now).
  8.  * Public domain.
  9.  *
  10.  * Written by <andreas.scherer@pobox.com>, March 7, 1998.
  11.  */
  12.  
  13. Options FailAt 21 /* Handle all error levels in this script */
  14.  
  15. MPX = "mpx" || Pragma( 'Id' ) /* Simulate `$$' = task number */
  16. NL = '0a'x /* `new line' character */
  17.  
  18. VERSION = "0.64"
  19.  
  20. MAKEMPX = "MakeMPX"
  21.  
  22. /*
  23.  * The following constructions simulate the macro expansion
  24.  * facility of UNIX "sh".  Most useful should be to call
  25.  *
  26.  *    rxset TEX "tex --progname=latex"
  27.  *
  28.  * in case you want to use the LaTeX typesetter for your
  29.  * labels in METAPOST graphics.  In addition to that you
  30.  * could set up a file mptexpre.tex in the working directory
  31.  * containing the necessary LaTeX preamble commands.  Or, if
  32.  * you want to use a global file instead, issue the call
  33.  *
  34.  *    rxset MPTEXPRE "<your-filename-here>"
  35.  *
  36.  * in order that MPTEXPRE points to the relevant file.  This
  37.  * file will be prepended to the intermediate (La)TeX output
  38.  * produced below.
  39.  */
  40. DMP = GetClip( "DMP" );
  41. If "" = DMP Then DMP = "dmp"
  42. DVITOMP = GetClip( "DVITOMP" );
  43. If "" = DVITOMP Then DVITOMP = "dvitomp"
  44. MPTEXPRE = GetClip( "MPTEXPRE" );
  45. If "" = MPTEXPRE Then MPTEXPRE = "mptexpre.tex"
  46. MPTOTEX = GetClip( "MPTOTEX" );
  47. If "" = MPTOTEX Then MPTOTEX = "mpto -tex"
  48. MPTOTR = GetClip( "MPTOTR" );
  49. If "" = MPTOTR Then MPTOTR = "mpto -troff"
  50. NEWER = GetClip( "NEWER" );
  51. If "" = NEWER Then NEWER = "newer"
  52. TEX = GetClip( "TEX" );
  53. If "" = TEX Then TEX = "tex"
  54. TROFF = GetClip( "TROFF" );
  55. If "" = TROFF Then TROFF = "Sorry, troff not available!"
  56.  
  57. /*
  58.  * These names are documented in the MetaPost manual, so it's
  59.  * unwise to change them.
  60.  */
  61. ERRLOG = "mpxerr.log" /* file for an error log if necessary */
  62. TEXERR = "mpxerr.tex" /* file for erroneous TeX if any */
  63. DVIERR = "mpxerr.dvi" /* troublesome dvi file if any */
  64. TROFF_INERR = "mpxerr" /* file for erroneous troff input, if any */
  65. TROFF_OUTERR = "mpxerr.t" /* file for troublesome troff output, if any */
  66.  
  67. USAGE = "Usage: rx "MAKEMPX" <mpfile> <mpxfile>." || NL
  68. USAGE = USAGE || "If <mpxfile> is older than <mpfile>, translate the" || NL
  69. USAGE = USAGE || "labels from the MetaPost input file <mpfile> to" || NL
  70. USAGE = USAGE || "low-level commands in <mpxfile>, by running" || NL
  71. USAGE = USAGE || "`"MPTOTEX",' `"TEX",' and `"DVITOMP".'" || NL || NL
  72. USAGE = USAGE || "The current directory is used for writing temporary files." || NL
  73. USAGE = USAGE || "Errors are left in `mpxerr.{tex,log,dvi}.'" || NL || NL
  74. USAGE = USAGE || "If the file specified with 'rxset MPTEXPRE <string>'" || NL
  75. USAGE = USAGE || "(mptexpre.tex by default) exists, it is prepended to the output" || NL
  76. USAGE = USAGE || "in tex mode." || NL || NL
  77. USAGE = USAGE || "Email bug reports to andreas.scherer@pobox.com."
  78.  
  79. MODE = "tex"
  80. MPFILE = ""
  81. MPXFILE = ""
  82.  
  83. Parse Arg PARAMETERS
  84. Parse Value PARAMETERS With PARAMETER PARAMETERS
  85.  
  86. Do While "" ~= PARAMETER
  87.   Select
  88.     When "-help" = PARAMETER | "--help" = PARAMETER Then Do
  89.       Say USAGE
  90.       Exit 0
  91.     End
  92.     When "-version" = PARAMETER | "--version" = PARAMETER Then Do
  93.       Say MAKEMPX VERSION "(AmiWeb2c 2.1)"
  94.       Say "There is NO warranty.  This script is public domain."
  95.       Say "Primary author: John Hobby; AmiWeb2c maintainer: A. Scherer."
  96.       Exit 0
  97.     End
  98.     When "-troff" = PARAMETER | "--troff" = PARAMETER Then
  99.       MODE = "troff"
  100.     When "-tex" = PARAMETER | "--tex" = PARAMETER Then
  101.       MODE = "tex"
  102.     When "-" = SubStr(PARAMETER,1,1) Then Do
  103.       Say MAKEMPX": "PARAMETER"? Try --help for more information."
  104.       Exit 1
  105.     End
  106.     Otherwise Do
  107.       If "" = MPFILE Then
  108.         MPFILE = PARAMETER /* input file */
  109.       Else If "" = MPXFILE Then
  110.         MPXFILE = PARAMETER /* output file */
  111.       Else Do
  112.         Say MAKEMPX": Extra argument "PARAMETER"; use --help if you need it."
  113.         Exit 1
  114.       End
  115.     End
  116.   End
  117.   Parse Value PARAMETERS With PARAMETER PARAMETERS
  118. End
  119.  
  120. If "" = MPFILE | "" = MPXFILE Then Do
  121.   Say MAKEMPX": Need exactly two file arguments. Try --help for more information."
  122.   Exit 1
  123. End
  124.  
  125. Address COMMAND "delete force quiet > NIL: "MPX".#?" ERRLOG TEXERR DVIERR
  126.  
  127. /*
  128.  * If MPXFILE is up-to-date, do nothing.
  129.  */
  130. Address COMMAND NEWER MPFILE MPXFILE
  131.  
  132. If 0 = RC Then Do /* 0 = TRUE in UNIX */
  133.  
  134.   /*
  135.    * Have to remake.
  136.    * Step 0: Check typesetter mode for consistency.
  137.    */
  138.   Select
  139.     When "tex" = MODE Then
  140.       MPTO = MPTOTEX
  141.     When "troff" = MODE Then
  142.       MPTO = MPTOTR
  143.     Otherwise Do
  144.       Say MAKEMPX": Unknown typesetter "MODE"."
  145.       Exit 1
  146.     End
  147.   End
  148.  
  149.   /*
  150.    * Step 1: Extract typesetter source from MetaPost source.
  151.    */
  152.   Address COMMAND MPTO MPFILE "-E"ERRLOG" > "MPX".tex"
  153.  
  154.   If 0 ~= RC Then Do
  155.     Say NL || "Command failed: "MPTO MPFILE
  156.     Address COMMAND "type" ERRLOG
  157.     Address COMMAND "delete force quiet "MPX".tex"
  158.     Exit 1
  159.   End
  160.  
  161.   /*
  162.    * Step 2: Run typesetter.
  163.    */
  164.   If "tex" = MODE Then Do
  165.  
  166.     If Exists( MPTEXPRE ) Then Do
  167.       /* Prepend user file. */
  168.       Address COMMAND "type "MPTEXPRE MPX".tex > "MPX".tmp"
  169.       Address COMMAND "copy "MPX".tmp" MPX".tex > NIL:"
  170.       Address COMMAND "delete force quiet "MPX".tmp > NIL:"
  171.     End
  172.  
  173.     Address COMMAND TEX "\batchmode \input "MPX".tex > NIL:"
  174.  
  175.     If 0 = RC Then Do
  176.       WHATEVER_TO_MPX = DVITOMP
  177.       INFILE = MPX".dvi"
  178.       INERROR = DVIERR
  179.     End
  180.     Else Do
  181.       Address COMMAND "copy "MPX".tex" TEXERR
  182.       Address COMMAND "copy "MPX".log" ERRLOG
  183.       Say NL || MAKEMPX": Command failed: "TEX TEXERR"; see "ERRLOG
  184.       Address COMMAND "delete force quiet "MPX".#?"
  185.       Exit 2
  186.     End
  187.  
  188.   End
  189.   Else If "troff" = MODE Then
  190.     TROFF /* Volunteers should come forward and fill this gap. */
  191.  
  192.   /*
  193.    * Step 3: Translate typesetter output to a MetaPost MPX.
  194.    */
  195.   Address COMMAND WHATEVER_TO_MPX INFILE MPXFILE ">" ERRLOG
  196.  
  197.   If 0 ~= RC Then Do /* Failure */
  198.     Address Command "copy "INFILE INERROR
  199.     Say NL || MAKEMPX": Command failed: "WHATEVER_TO_MPX INFILE MPXFILE
  200.     Address Command "type" ERRLOG
  201.     Address Command "delete force quiet "MPX".#?"
  202.     # Better to remove MPXFILE if something went wrong rather than
  203.     # leaving behind an unfinished or unusable version since NEWER
  204.     # might think that all is fine if MPXFILE exists.
  205.     Address Command "delete force quiet "MPXFILE
  206.     Exit 3
  207.   End
  208.  
  209.   Address Command "delete force quiet "MPX".#?" ERRLOG
  210.  
  211. End
  212.  
  213. Exit 0
  214.